<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page');
	$return['setting']['balance_money']=$this->zhaoshang['balance_money_start'];
	$data=array();
	$data['commission_total']=$this->sum('commission',array('mid'=>$_SESSION['uid']),'money');
	$data['commission_0']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'status'=>0),'money');
	//待结算佣金
	$data['commission_1']=$this->sum('commission',array('mid'=>$_SESSION['uid'],'status'=>1),'money');
	//可结算佣金
	$params=array('mid'=>$_SESSION['uid'],'status'=>1);
	if($this->zhaoshang['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->zhaoshang['balance_day'])*86400;
		$params['complete_time <']=$time;
	}
	$data['commission_1_1']=$this->sum('commission',$params,'money');
	$data['balance_total']=$this->sum('balance',array('mid'=>$_SESSION['uid']),'money');
	$data['balance_1']=$this->sum('balance',array('mid'=>$_SESSION['uid'],'status'=>1),'money');
	$data['balance_2']=$this->sum('balance',array('mid'=>$_SESSION['uid'],'status'=>2),'money');
	$data['balance_3']=$this->sum('balance',array('mid'=>$_SESSION['uid'],'status'=>3),'money');
	$data['balance_pay']=$this->sum('balance',array('mid'=>$_SESSION['uid'],'status'=>3),'balance_pay');
	foreach($data as &$row){
		$row=price($row);
	}
	$return['data']=$data;
	$return['pay_types']=$this->pay_types;
	$pay_type='credit';
	set_html('title',$return['setting']['tcommission1']?:'分销佣金');
	exi($return);
}
//结算
if($_RQ['op']=='balance'){
	$post=get_postdata();
	$this->model('commission')->create_balance($_SESSION['uid'],$post);
	exi('结算成功！','','main');
}
?>